import { getDepartments, getRoles } from '@/service/modules/system'
import type { DepartmentModel, RoleModel } from '@/types'
import { defineStore } from 'pinia'

interface commonStoreState {
  roles: RoleModel[]
  departments: DepartmentModel[]
}

const useCommonStore = defineStore('common', {
  state: (): commonStoreState => ({
    roles: [],
    departments: [],
  }),
  actions: {
    async getRolesAction() {
      const pageParams = { page_size: 100, page_index: 1 }
      const { data: result } = await getRoles(pageParams)
      this.roles = result.rows
    },
    async getDepartmentsAction() {
      const pageParams = { page_size: 100, page_index: 1 }
      const { data: result } = await getDepartments(pageParams)
      this.departments = result.rows
    },
  },
})

export default useCommonStore
